package com.asset.dispoal.channel.service.common;


import com.asset.dispoal.channel.domain.db.mapper.SysChannelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.math.BigDecimal;

/**
 * @author qr
 * @date 2022/3/25$
 */
@Component
public class SysChannelDebtDelCommand implements BaseCommand<String, Result> {

    @Autowired
    SysChannelMapper sysChannelMapper;

    @Override
    public Result execute(String id) {
        BigDecimal decimal = sysChannelMapper.getDebtMoney(id);
        String channelId = sysChannelMapper.debtGetByChannelId(id);
        sysChannelMapper.debtDelete(id);
        sysChannelMapper.addTotalMoney(BigDecimal.ZERO.subtract(decimal), channelId);
        return Result.ok();
    }
}
